package com.zgm.ch04.applicationContext.event._9_8;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class EventPublisherDemo implements ApplicationContextAware {
	
	private ApplicationContext ctx;
	
	public static void main(String[] args){
		ApplicationContext context = new ClassPathXmlApplicationContext("com/zgm/ch04/applicationContext/event/_9_8/_9_8-context.xml");
		
		EventPublisherDemo eventPublisherDemo = (EventPublisherDemo) context.getBean("eventPublisherDemo");
		eventPublisherDemo.publish("周浩，你好");
		eventPublisherDemo.publish("周光明，你好");
		
		System.out.println("结束！");
	}
	
	public void publish(String message){
		this.ctx.publishEvent(new MessageEvent(this, message));
	}
	
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.ctx = applicationContext;
	}
	

}
